%% Test file
clear all
clc




x_nodes = [0,1 ; 1,1 ; 1,2 ; 2,4 ; 2,3 ; 0.5 , 0.5 ; 0.25,0.25 ; 1.25 , 1.25 ; 1.00 , 1.2  ];
x_sample = [ 1 , 0.5];


nPt = size (x_nodes(:,1))
nPts = nPt(1)
rho = 1;
order = 2;
poliBaseType = 'comelaGoga'
dimension = size(x_sample,2);

for i=1:nPts
    dist = norm (x_sample - x_nodes(i,:));
    w(i) = gaussianWeight (dist , rho);
end

B = assemblyBMatrix( x_sample, x_nodes, order , w , poliBaseType);

A = assemblyMomentMatrix ( x_sample, x_nodes, w , poliBaseType, order );

p = poliBase (x_sample,order,poliBaseType);

alpha = solveAlpha (A,p);

N = alpha * B';




%% Calculamos el gradiente de las funciones de forma

gradP = gradPoliBase (x_sample,order,poliBaseType);

gradWeights = gradGaussianWeight (x_nodes,x_sample,rho);

gradA = assemblyGradMomentMatrix (x_sample , x_nodes , gradWeights , poliBaseType , order);

loadVectorGradAlpha = assemblyLoadVectorGradAlpha ...
                        ( gradP(:,1) , gradP (:,2) , gradA(:,:,1) , gradA(:,:,2) , alpha );

for d=1 : dimension                    
    gradAlpha(:,d) = solveAlpha (A,loadVectorGradAlpha(:,d)');
end

gradB = assemblyGradBMatrix (x_sample,x_nodes,order,gradWeights,poliBaseType);

for d=1:dimension
gradN(:,d) = gradAlpha(:,d)' * B' +  alpha * gradB(:,:,d)';
end
                    
                    

